/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tools.settings.gui;

/**
 *
 * @author Pieter Backaert
 */


import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;


public class SelectEGui extends JFrame implements ActionListener {

    private JFrame frame;
    private JPanel panel;
    private JButton customButton;
    private JButton legislationButton;
    private double eValue = 0;
    private JTextField textfield;
    private JComboBox comboBox;
    private String[] legislationScope = { "Brussel", "Belgium", "Europe" };

    private JLabel label1;

    private boolean not_done=true;

    private double eLimit;
    private String legislation;

    public double getELimit() {
        return eLimit;
    }

    public String getLegislation() {
        return legislation;
    }

    public boolean getNotDone(){
        return not_done;
    }

    public SelectEGui(){
        frame = new JFrame("Coverage for wireless networks");
        panel = new JPanel();


        panel.setLayout(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();

        label1 = new JLabel("Please input Electrical Field Strength [V/m] : ");
        gbc.fill = GridBagConstraints.NONE;
        gbc.insets = new Insets(4, 4, 4, 4);
        gbc.weightx = 0;
        gbc.weighty = 0;
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.gridwidth = 1;
        gbc.fill = GridBagConstraints.NONE;
        gbc.anchor = GridBagConstraints.WEST;
        panel.add(label1, gbc);


        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.fill = GridBagConstraints.NONE;
        textfield = new JTextField("3");
        textfield.setColumns(5);
        textfield.setEditable(true);
        panel.add(textfield, gbc);

        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.anchor = GridBagConstraints.CENTER;
        panel.add(new JLabel("OR"), gbc);


        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.anchor = GridBagConstraints.WEST;
        panel.add(new JLabel("Select Legislation:"), gbc);


        
        comboBox = new JComboBox(legislationScope);
        comboBox.setSelectedIndex(1);
        gbc.gridx = 1;
        gbc.gridy = 2;
        gbc.anchor = GridBagConstraints.WEST;
        panel.add(comboBox, gbc);

        
        gbc.gridx = 0;
        gbc.gridy = 3;
        gbc.anchor = GridBagConstraints.EAST;
        customButton = new JButton("CUSTOM E[V/m] value");
        customButton.addActionListener(this);
        panel.add(customButton, gbc);

        gbc.gridx = 1;
        gbc.gridy = 3;
        gbc.anchor = GridBagConstraints.WEST;
        legislationButton = new JButton("LEGILASTION");
        legislationButton.addActionListener(this);
        panel.add(legislationButton, gbc);




        frame.setSize(256,256);
        frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
        frame.getContentPane().add(panel);



        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension size = frame.getSize();
        screenSize.height = screenSize.height/2;
        screenSize.width = screenSize.width/2;
        size.height = size.height/2;
        size.width = size.width/2;
        int y = screenSize.height - size.height;
        int x = screenSize.width - size.width;
        frame.setLocation(x, y);

        frame.pack();
        frame.setVisible(true);
        frame.show();
    }



    public double getEValue() {
        return eValue;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if(customButton == e.getSource()) {
            textfield.setColumns(5);
       
            eLimit = Double.parseDouble(textfield.getText());
            legislation = "";
            not_done = false;

            frame.dispose();
     
        }
        if(legislationButton == e.getSource()) {
            textfield.setColumns(5);

            eLimit = 0;
            legislation = (String) comboBox.getSelectedItem();
            not_done = false;
 
            frame.dispose();
        }


    }


    public static void main(String[] args){
          SelectEGui sEgui = new SelectEGui();
    }

}

